//
//  SIXMeController.m
//  weibo
//
//  Created by chenangel on 16/5/20.
//  Copyright © 2016年 chuhan. All rights reserved.
//

#import "SIXMeController.h"
#import "SIXUserInfoViewController.h"
#import "SIXAccountTool.h"
#import "SIXAccount.h"

#define kSectionsNumber 7
#define kTableViewMin 8
#import "SIXMeController.h"
#import "SIXHeadViewCell.h"
#import "SIXMeModels.h"
#import "AFNetworking.h"
#import "MJExtension.h"
#import "SIXMeNewfriendVC.h"
#import "SIXFriendTableController.h"
#import "SIXMeSettingVC.h"

@interface SIXMeController ()
@property (strong, nonatomic) NSDictionary *dataArray;

@property (strong, nonatomic) SIXMeModels *models;

@property (nonatomic,strong)NSMutableArray *arr;

@property (nonatomic, strong) NSDictionary *responseObject;

@end

@implementation SIXMeController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    //初始化tableView
    [self tabledefault];
    [self barButtonItem];
    
    [SIXNoteCenter addObserver:self selector:@selector(userInfoVC) name:@"UserInfo" object:nil];
}

#pragma mark - 初始化TableView
- (void)tabledefault{
    self.tableView.contentInset = UIEdgeInsetsMake(kTableViewMin, 0, 0, 0);
}
#pragma mark - UItableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    if (cell.contentView.tag == 1) {
        SIXMeNewfriendVC *vc =   [[SIXMeNewfriendVC alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }
    if (cell.contentView.tag == 2) {
    }
    if (cell.contentView.tag == 3) {
    }
    if (cell.contentView.tag == 4) {
    }
    if (cell.contentView.tag == 5) {
    }
    if (cell.contentView.tag == 6) {
    }
    if (cell.contentView.tag == 7) {
    }
    if (cell.contentView.tag == 8) {
    }
    if (cell.contentView.tag == 9) {
    }
    if (cell.contentView.tag == 10) {
    }
    if (cell.contentView.tag == 11) {
    }
}
#pragma mark - headView - 本地plist
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        SIXHeadViewCell *HeadView = [[[ NSBundle mainBundle ] loadNibNamed:@"SIXHeadViewCell" owner:nil options:nil]lastObject];
        NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"SIXMe" ofType:@"plist"]];
        HeadView.models = [SIXMeModels modelsWithDict:dict];
        return HeadView;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 135;
    }
    return 0;
}


#pragma mark - 懒加载
- (NSDictionary *)dataArray{
    if (_dataArray == nil) {
        _dataArray = [NSDictionary dictionary];
    }
    return _dataArray;
}

-(NSMutableArray *)arr{
    if (_arr == nil) {
        _arr = [NSMutableArray array];
    }
    return _arr;
}

#pragma mark - UIBarButtonItem
- (void)barButtonItem {
    UIBarButtonItem *itemLeft = [[UIBarButtonItem alloc] initWithTitle:@"添加好友" style:UIBarButtonItemStyleDone target:self action:@selector(leftBtnClick)];
    itemLeft.tintColor = [UIColor grayColor];
    
    self.navigationItem.leftBarButtonItem = itemLeft;
    
    
    UIBarButtonItem *itemRight = [[UIBarButtonItem alloc] initWithTitle:@"设置" style:UIBarButtonItemStyleDone target:self   action:@selector(pushSetting)];
    itemRight.tintColor = [UIColor grayColor];
    //设置右侧button
    self.navigationItem.rightBarButtonItem = itemRight;
}
-(void)leftBtnClick{
    
    SIXFriendTableController *vc = [[SIXFriendTableController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
    
}
- (void)json{
    NSURL *url = [NSURL URLWithString:@"https://api.weibo.com/2/users/show.json?access_token=2.00khaCOGTp5MdD67ff0bacddLzrtuC&uid=5704283448"];
    
    [[[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        
        //解析数据
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
        //        NSArray *arr = dict[@"videos"];
        NSLog(@"%@",[NSThread currentThread]);
        
        //字典转模型  字典数组-->模型数组
        
        [self.arr addObject:[SIXMeModels modelsWithDict:dict]];
        
    }] resume];
}

#pragma mark -- 测试user
- (void)testUser{
    self.view.backgroundColor = [UIColor redColor];
    UIButton *apibtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [apibtn setTitle:@"跳转进个人按钮" forState:UIControlStateNormal];
    [apibtn setTitle:@"跳转进个人按钮" forState:UIControlStateSelected];
    apibtn.frame = CGRectMake(150, 250, 120, 50);
    [apibtn addTarget:self action:@selector(userInfoVC) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:apibtn];
}
- (void)userInfoVC{
    //SIXUserInfoViewController *apiVC = [[SIXUserInfoViewController
    
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"SIXUserInfoViewController" bundle:nil];
    UIViewController *vc = [sb instantiateInitialViewController];
    
    SIXAccount *acount = [SIXAccountTool account];
    SIXLog(@"userInfoVC-access_token-----%@-------%@",acount.access_token,acount.uid);
    
    [self.navigationController pushViewController:vc animated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark - pushSetting
- (void)pushSetting{
    SIXMeSettingVC *vc =   [[SIXMeSettingVC alloc] initWithStyle:UITableViewStyleGrouped];
    
    [self.navigationController pushViewController:vc animated:YES];
    
}
@end
